import { _decorator, Component, Label, Node, v2, Vec2 } from 'cc';
const { ccclass, property, executeInEditMode } = _decorator;

@ccclass('dot_test')
@executeInEditMode
export class dot_test extends Component {
    @property(Node)
    node_1: Node = null!;

    @property(Node)
    node_2: Node = null!;

    @property(Label)
    label: Label = null!;

    @property(Label)
    label2: Label = null!;

    start() {}

    protected update(dt: number): void {
        const vec2_1 = v2(this.node_1.position.x, this.node_1.position.y).normalize();

        const vec2_2 = v2(this.node_2.position.x, this.node_2.position.y).normalize();

        const d = Vec2.dot(vec2_1, vec2_2);

        const cross = Vec2.cross(vec2_1, vec2_2);
        this.label.string = 'dot:' + d.toFixed(2);
        this.label2.string = 'cross:' + cross.toFixed(2);
    }
}
